'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 市场
 * @author sundbcn@gmail.com (sun debing)
 */

var moment = require('moment');
var modelUtil = require('../util/modelUtil');
var _ = require('lodash');
var mongoConnector = require('../libs/mongodb/mongoConnector');
/* jshint unused:false */
var marketSchema = require('../schemas/market/marketSchema');
var Market = mongoConnector().model('Market');
var constantUtil = require('../util/constantUtil');

var marketModel = module.exports;

marketModel.getByRoleId = function (role_id, cb) {
    modelUtil.getByRoleId(Market, role_id, function (err, market_model) {
        if (!!err) {
            console.error(err);
            return cb(err);
        }

        cb(null, market_model);
    });
};

/**
 * 5点刷新
 */
module.exports.onFiveRefresh = function (self, cb) {
    var market_model = self;
    var market_free_refresh_times = constantUtil.value('market_free_refresh_times') + market_model.vip_free_times;
    if (market_model.free_times < market_free_refresh_times) {
        market_model.free_times = market_free_refresh_times;
    }
    cb();
};
